package com.jm.springboot21.controller;

import com.jm.springboot21.pojo.Student;
import com.jm.springboot21.pojo.Result;
import com.jm.springboot21.pojo.Student;
import com.jm.springboot21.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;

@RestController
@RequestMapping("/student")
@CrossOrigin("*")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result findAll(){
        java.util.List<Student> all = studentService.findAll();
        return Result.success(all);
    }
    @PostMapping
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        studentService.deleteById(id);
        return Result.success();
    }
    @DeleteMapping
    public Result deleteByIds(@RequestBody java.util.List<Integer> ids){
        studentService.deleteByIds(ids);
        return Result.success();
    }
    @PutMapping
    public Result updateById(@RequestBody Student student){
        studentService.updateById(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Student student = studentService.findById(id);
        return Result.success(student);
    }
    @GetMapping("/name")
    public Result findByName(@RequestParam String name){
        List<Student> students = studentService.findByName(name);
        return Result.success(students);
    }
    //总人数
    @GetMapping("/count")
    public Result count(){
        Integer count = studentService.count();
        return Result.success(count);
    }
}
